package com.woniuxy.controller;


import com.woniuxy.demo.Result;
import com.woniuxy.dto.PageEvaluationDto;
import com.woniuxy.enums.CodeEnum;
import com.woniuxy.exception.PawnRoleException;
import com.woniuxy.param.AddGoodsEvaluationParam;
import com.woniuxy.param.ListEvaluationParam;
import com.woniuxy.service.GoodsEvaluationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 评估相关 前端控制器
 * </p>
 *
 * @author zcx, ftl, gr, rhs
 * @since 2022-01-04
 */
@Slf4j
@RestController
@RequestMapping("/goods-evaluation")
@Api(tags = "商品评估管理接口")
//商品评估
public class GoodsEvaluationController {

    @Autowired
    private GoodsEvaluationService goodsEvaluationService;

    /**
     * 添加商品评估信息
     *
     * @param addGoodsEvaluationParam
     * @return
     */
    @ApiOperation("添加商品评估信息")
    @PostMapping("/addEvaluation")
    public Result addGoodsEvaluation(@RequestBody AddGoodsEvaluationParam addGoodsEvaluationParam) {
        if (goodsEvaluationService.addGoodsEvaluation(addGoodsEvaluationParam)) {
            return new Result().setCode(200).setMsg("添加成功");
        }
        throw new PawnRoleException(CodeEnum.GOODS_EVALUATION_SAVE_FAIL.getMessage(), CodeEnum.GOODS_EVALUATION_SAVE_FAIL.getCode());
    }

    /**
     * 查询商品评估信息
     *
     * @param listEvaluationParam
     * @return
     */
    @ApiOperation("查询商品评估信息")
    @GetMapping("/queryEvaluation")
    public Result queryEvaluation(ListEvaluationParam listEvaluationParam) {
        PageEvaluationDto pageEvaluationDto = goodsEvaluationService.listEvaluation(listEvaluationParam);
        return Result.newInstance().setCode(200).setMsg("查询成功").setData(pageEvaluationDto);
    }


    /**
     * 批量删除商品评估(逻辑删除)
     *
     * @param ids
     * @return
     */
    @ApiOperation("批量删除商品评估(逻辑删除)")
    @PostMapping("/removeEvaluationByIds.do")
    public Result removeEvaluationByIds(@RequestBody List<Integer> ids) {
        if (goodsEvaluationService.removeEvaluationByIds(ids)) {
            return Result.newInstance().setCode(200).setMsg("删除成功");
        }
        throw new PawnRoleException(CodeEnum.GOODS_EVALUATION_DELETE_FAIL.getMessage(), CodeEnum.GOODS_EVALUATION_DELETE_FAIL.getCode());
    }
    @ApiOperation("根据id查询评估信息")
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable("id") Integer id){

        return new Result().newInstance().setMsg("查询成功").setCode(200).setData(goodsEvaluationService.findById(id));
    }



}

